#!/bin/bash

#编译动态连接库
clear

cd drv_db
rm -rf build
mkdir build

rm -rf lib_custom_drv_db
mkdir lib_custom_drv_db
mkdir lib_custom_drv_db/include
mkdir lib_custom_drv_db/lib

cd build
clear
if [ "$1" = "arm" ]; then
	echo "cmake ARM 架构动态库"
	cmake ../ -DFRAME=arm
else
	echo "cmake PC 架构动态库"
	cmake ../
fi
make -j8

# 检查编译是否成功
LIB_PATH="libcustom_drv_db.so"

if [ -f "$LIB_PATH" ]; then
	echo "动态库已生成"
else
	echo "未找到动态库文件！"
	exit 1
fi

#拷贝动态连接库
cd ..
rm -rf lib_custom_drv_db
mkdir lib_custom_drv_db

mkdir lib_custom_drv_db/lib
cp build/lib* lib_custom_drv_db/lib/.

mkdir lib_custom_drv_db/include
cp ./*.h lib_custom_drv_db/include/.

cd ..
mkdir lib
rm -rf lib/lib_custom_drv_db
mv drv_db/lib_custom_drv_db ./lib

#编译demo
# clear

rm -rf build
mkdir build
cd build

if [ "$1" = "arm" ]; then
	echo "cmake ARM 架构 DEMO"
	cmake ../ -DFRAME=arm
else
	echo "cmake PC 架构 DEMO"
	cmake ../
fi
make -j8

cd ..

#生成运行环境
rm -rf run_sql_demo
mkdir run_sql_demo
cp build/SQL_DEMO run_sql_demo/.
cp lib/lib_custom_drv_db run_sql_demo/. -rf
cp test_db run_sql_demo/. -rf
cp run_demo.sh run_sql_demo/.

cp run_sql_demo ~/Public/. -rf

if [ "$1" = "arm" ]; then
	echo "cmake ARM 架构 生成运行环境"
else
	echo "cmake PC 架构 运行demo"
	#运行demo
	cd run_sql_demo
	./run_demo.sh
fi